package com.woniuxy.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @program: bookstore
 * @description:
 * @create: 2024-09-28 10:00
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResponseData<T> {
    private Integer code;
    private String msg;
    private T data;

    /***
     * 封装的方法，成功调用
     * @return
     */
    public ResponseData ok() {
        return new ResponseData(ResponseEnum.OK.getCode(), ResponseEnum.OK.getMsg(), null);
    }

    public ResponseData ok(T data) {
        return new ResponseData(ResponseEnum.OK.getCode(), ResponseEnum.OK.getMsg(), data);
    }

    /**
     * 接口失败返回的方法
     *
     * @return
     */
    public ResponseData fail(ResponseEnum responseEnum) {
        return new ResponseData(responseEnum.getCode(), responseEnum.getMsg(), null);
    }
}
